class MedianFinder {
    // 较小的部分称为左侧部分，较大的部分称为右侧部分：
    // 将左侧部分放入大根堆中，然后将右侧元素放入小根堆中，
    priority_queue<int> left; // ⼤根堆
    priority_queue<int, vector<int>, greater<int>> right; // ⼩根堆
 
public:
    MedianFinder() {
 
    }
    
    void addNum(int num) {
        if(left.size() == right.size())
        {
            if(right.empty() || left.top() > num)
            {
                left.push(num);
            }
            else
            {
                right.push(num);
                left.push(right.top());
                right.pop();
            }
        }
        else
        {
            if(left.top() > num)
            {
                left.push(num);
                right.push(left.top());
                left.pop();
            }
            else
            {
                right.push(num);
            }
        }
    }
    double findMedian() {
        if(left.size() == right.size())
            return (left.top() + right.top()) / 2.0;
        return left.top();
    }
};
 
/**
 * Your MedianFinder object will be instantiated and called as such:
 * MedianFinder* obj = new MedianFinder();
 * obj->addNum(num);
 * double param_2 = obj->findMedian();
 */